package me.imli.app.ui.adapter;

import java.util.ArrayList;
import java.util.List;

import android.widget.BaseAdapter;

public abstract class IBaseAdapter<T> extends BaseAdapter {
	
	protected final String TAG = getClass().getName();
	
	// list数据
	protected List<T> list = new ArrayList<T>();
	
	public void update(List<T> list) {
		if (list == null) return;
		try {
			this.clear();
			this.list.addAll(list);
			this.notifyDataSetChanged();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void clear() {
		this.list.clear();
		this.notifyDataSetChanged();
	}
	
	public void insert(T t) {
		this.list.add(t);
	}
	
	public void insert(T t, int location) {
		this.list.add(location, t);
	}

	public void remove(T t) {
		this.list.remove(t);
	}
	
	public void remove(int location) {
		this.list.remove(location);
	}
	
	@Override
	public int getCount() {
		return list.size();
	}
	
	@Override
	public T getItem(int position) {
		return list.get(position);
	}
	
	@Override
	public long getItemId(int position) {
		return position;
	}
	
	/**
	 * 
	 * @author Doots
	 *
	 */
	public abstract class IBaseHolder {

	}
}
